package org.example.libApp;

import org.example.libCore.Book;
import org.example.libCore.LibraryManager;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    static class SimpleLibraryManager implements LibraryManager {
        private List<Book> books = new ArrayList<>();

        @Override
        public void addBook(Book book) {
            books.add(book);
        }

        @Override
        public void removeBook(int id) {
            books.removeIf(book -> book.getId() == id);
        }

        @Override
        public List<Book> listBooks() {
            return books;
        }
    }

    public static void main(String[] args) {
        LibraryManager manager = new SimpleLibraryManager();
        Scanner scanner = new Scanner(System.in);

        while (true) {
            System.out.println("1. Add Book");
            System.out.println("2. Remove Book");
            System.out.println("3. List Books");
            System.out.println("4. Exit");
            System.out.print("Choose an option: ");
            int choice = scanner.nextInt();

            if (choice == 1) {
                System.out.print("Enter book ID: ");
                int id = scanner.nextInt();
                scanner.nextLine();
                System.out.print("Enter book title: ");
                String title = scanner.nextLine();
                System.out.print("Enter author: ");
                String author = scanner.nextLine();
                System.out.print("Enter year published: ");
                int yearPublished = scanner.nextInt();
                manager.addBook(new Book(id, title, author, yearPublished));
            } else if (choice == 2) {
                System.out.print("Enter book ID to remove: ");
                int id = scanner.nextInt();
                manager.removeBook(id);
            } else if (choice == 3) {
                for (Book book : manager.listBooks()) {
                    System.out.println(book);
                }
            } else if (choice == 4) {
                break;
            }
        }
        scanner.close();
    }
}